let container = document.querySelector('#container');
let domStr="";
function render(data, el){
    data.forEach(item => {
        // let li = document.createElement('li');        
        let regExp = /(?<=imgurl=)[^'"]*/
        let result = item.productImg2.match(regExp)  
        domStr+=`<li productid="${item.productId}">
        <a>            
            <div class="img fl" >
                <img height="100" width:"100" src="${result[0]}" alt="" productid="${item.productId}">
            </div>            
            <div class="infoR" >                
                <div class="title" >
                    <h4 >${item.productName}
                        <span>${item.productPinkage}</span>
                    </h4>
                </div>                
                <div class="other" >
                    <span class="mall fl">${item.productFrom}|${item.productTime}<span>
                    <em class="fr" >
                    <span >${item.productComCount}</span>
                    <img width="16" height="16" src="./../assets/images/对话信息.png" alt="" >                   
                    </em>   
                </div>   
            </div>
        </a></li>
    `    
    })
    container.innerHTML = domStr;
}
//首次发起页面请求
function getData(pageid = 1) {
    fetch(`http://chst.vip:1234/api/getmoneyctrl?pageid=${pageid}`)
           
        .then(body => body.json())
        .then(res => {
            console.log(res)
            render(res.result, container)
        })
}
getData() //首次调用

//声明初始的pageid
let pageid = 1;

lazyLoad(function () {
    // 在这里发送请求
    pageid++
    if (pageid > 14) {
        alert('服务器没有更多数据了')
        return
    }
    //pageid最多到14;超过了 服务器就没有数据响应了
    getData(pageid)
    
}, 100)

container.onclick=function(e){
    if(e.target.localName='li'){
        let _this=e.target;
        let id=_this.getAttribute('productid');
        // console.log(id)
        location.href="./../pages/producte_detail.html?productid="+id;
    }
}
